home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / amos / amcafext.lha / AMCAF_Examples / VecRotSolid.AMOS / VecRotSolid.amosSourceCode
AMOS Source Code  |  1995-07-14  |  3KB  |  118 lines

  1. ' ************************************* Commands used: 
  2. ' *                                   * Vec Rot Pos        Blitter Clear 
  3. ' *           Amcaf Examples          * Vec Rot Angles     =Qsin 
  4. ' *     Vector Rotate Solid V1.1      * Vec Rot Precalc
  5. ' *      Written by Chris Hodges      * =Vec Rot X 
  6. ' *                                   * =Vec Rot Y 
  7. ' ************************************* =Vec Rot Z 
  8. '                          
  9. ' Kill the mouse 
  10. Hide 
  11. ' Setup a nice little screen with double buffering 
  12. Screen Open 0,320,256,8,Lowres
  13. Curs Off : Flash Off : Paper 0 : Pen 1 : Cls 
  14. Palette 0,$F44,$4F4,$FF4,$44F,$F4F,$4FF
  15. Double Buffer 
  16. Autoback 0
  17. ' Read out, how many coords are used.
  18. Restore COORDS
  19. Read NUMCO
  20. ' Dim one field to keep these coords, and a second for the rotated.
  21. Dim CO(NUMCO,2),RC(NUMCO,1)
  22. ' Now read all coords in.
  23. For A=1 To NUMCO
  24.   Read CO(A,0),CO(A,1),CO(A,2)
  25. Next 
  26. ' Then, get the number of shapes the object consists of. 
  27. Restore SHAPES
  28. Read NUMLI
  29. ' Dim a field to hold the four coords. 
  30. Dim LI(NUMLI,4)
  31. ' Get the datas. 
  32. For A=1 To NUMLI
  33.   Read LI(A,0),LI(A,1),LI(A,2),LI(A,3)
  34.   Read LI(A,4)
  35. Next 
  36. ' Set the three angles. Remember that these are non standard angles, 
  37. ' one full rotation is at 1024, not 360! 
  38. AX=0 : AY=512 : AZ=128
  39. Repeat 
  40.   ' Start clearing bitplane 0. 
  41.    Extension_8_121C 0,0
  42.   ' While the blitter is working, use the time to calculate the rotations. 
  43.   ' Move and set the angles. 
  44.   Add AX,5
  45.   Add AY,8
  46.   Add AZ,11
  47.    Extension_8_1138 AX,AY,AZ
  48.   ' Calculate the distances by using a sine-function and the three angles. 
  49.   POSX= Extension_8_1106(AX,300)
  50.   POSY= Extension_8_1106(AY,300)
  51.   POSZ= Extension_8_1106(AZ,500)+1500
  52.   ' Set the camera positions.
  53.    Extension_8_1122 POSX,POSY,POSZ
  54.   ' Now it's time to compute the matrix. 
  55.    Extension_8_1152 
  56.   ' Clear bitplane 1 
  57.    Extension_8_121C 0,1
  58.   ' So let's rotate all coordinates of the field CO()
  59.   For A=1 To NUMCO
  60.     ' Note: You only have to use the vec rot function with parameters once.
  61.     RC(A,0)= Extension_8_1168(CO(A,0),CO(A,1),CO(A,2))+160
  62.     RC(A,1)= Extension_8_1184 +128
  63.   Next 
  64.   ' Clear bitplane 2 
  65.    Extension_8_121C 0,2
  66.   ' It's time to finally get the polygons to the screen! 
  67.   For A=1 To NUMLI
  68.     ' Get the four coordinates pairs.  
  69.     C1=LI(A,0) : C2=LI(A,1) : C3=LI(A,2) : C4=LI(A,3)
  70.     CO=LI(A,4)
  71.     ' Get the rotated coordinates
  72.     X1=RC(C1,0) : Y1=RC(C1,1)
  73.     X2=RC(C2,0) : Y2=RC(C2,1)
  74.     X3=RC(C3,0) : Y3=RC(C3,1)
  75.     X4=RC(C4,0) : Y4=RC(C4,1)
  76.     ' Use some maths, to see if the plane faces into the camera or into
  77.     ' the back. This formula works ONLY, if the polygon is drawn 
  78.     ' anticlockwise!   
  79.     DI=(X3-X1)*(Y2-Y1)-(X2-X1)*(Y3-Y1)
  80.     If DI<0
  81.       ' Draw the polygons in colour CO 
  82.       Ink CO
  83.       Polygon X1,Y1 To X2,Y2 To X3,Y3 To X4,Y4
  84.     End If 
  85.   Next 
  86.   ' Swap the screens to bring the object to view.
  87.   Screen Swap 
  88.   Wait Vbl 
  89. Until Inkey$=Chr$(27) or Mouse Key<>0
  90. Screen Close 0
  91. End 
  92. '  1_____2   
  93. ' 5/____/| 
  94. ' | |  |6| 
  95. ' |4|__|_|3  
  96. ' |/___|/
  97. ' 8    7 
  98. COORDS:
  99.   Data 8
  100. ' CUBE 
  101.   Data -100,-100,-100
  102.   Data 100,-100,-100
  103.   Data 100,-100,100
  104.   Data -100,-100,100
  105.   Data -100,100,-100
  106.   Data 100,100,-100
  107.   Data 100,100,100
  108.   Data -100,100,100
  109.  
  110. SHAPES:
  111.   Data 6
  112. ' All lines are drawn in anticlockwise.
  113.   Data 1,2,6,5,1
  114.   Data 4,3,2,1,2
  115.   Data 2,3,7,6,3
  116.   Data 3,4,8,7,4
  117.   Data 4,1,5,8,5
  118.   Data 6,7,8,5,6